<?php

declare (strict_types=1);
namespace App\Model;

/**
 * @property int $id
 * @property int $uid
 * @property int $blocked_uid
 * @property int $create_time
 */
class UserBlacklist extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'user_blacklist';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['id', 'uid', 'blacked_uid', 'create_time'];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'uid' => 'integer', 'blocked_uid' => 'integer', 'create_time' => 'integer'];

    public static function getMyBlackList(int $uid)
    {
        $select = "zx_b.uid,zx_b.name as nickname,zx_d.username as num,zx_b.type,zx_b.direction,zx_c.head,ifnull(zx_d.online,0) as online,ifnull(zx_d.service_status,0) as service_status";
        $model = ConsultantDatum::from('user_blacklist as a')
            ->rightJoin('consultant_datum  as b', 'a.blacked_uid', '=', 'b.uid')
            ->leftJoin('user_datum as c', 'a.blacked_uid', '=', 'c.id')
            ->leftJoin('chat_user as d', 'd.uid', '=', 'a.blacked_uid')
            ->where(['a.uid' => $uid, 'b.status' => 1])
            ->selectRaw($select)
            ->orderBy('a.create_time', 'desc');


        return page($model);


    }
}
